package com.golden.procedure.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.golden.procedure.dao.WorkSeatSchedulingMapper;
import com.golden.procedure.dao.WorkSiteSchedulingMapper;
import com.golden.procedure.dao.WorkSiteSeatMapper;
import com.golden.procedure.domain.WorkOrderBookDO;
import com.golden.procedure.domain.WorkSchedulingSettingDO;
import com.golden.procedure.domain.WorkSeatSchedulingDO;
import com.golden.procedure.domain.WorkSiteSchedulingDO;
import com.golden.procedure.domain.WorkSiteSeatDO;
import com.golden.procedure.domain.WorkerDO;
import com.golden.procedure.domain.WorkerRoleDO;
import com.golden.procedure.entity.WorkSeatScheduling;
import com.golden.procedure.entity.WorkSeatSchedulingExample;
import com.golden.procedure.entity.WorkSiteSeat;
import com.golden.procedure.entity.WorkSiteSeatExample;
import com.golden.procedure.query.SchedulingQueryDO;
import com.golden.procedure.query.WorkOrderBookQueryDO;
import com.golden.procedure.query.WorkerQueryDO;
import com.golden.procedure.query.WorkerRoleQueryDO;
import com.golden.procedure.result.ResultDO;
import com.golden.procedure.result.ResultSupport;
import com.golden.procedure.service.IWorkOrderBookService;
import com.golden.procedure.service.IWorkOrderService;
import com.golden.procedure.service.IWorkSeatSchedulingService;
import com.golden.procedure.service.IWorkSiteSchedulingService;
import com.golden.procedure.service.IWorkSiteSeatService;
import com.golden.procedure.service.IWorkerService;
import com.golden.procedure.util.BeanUtilsExtends;
import com.golden.procedure.util.BonConstant;

@Service("workSiteSeatService")
public class WorkSiteSeatService extends BaseService implements IWorkSiteSeatService {

	@Autowired
	WorkSiteSeatMapper workSiteSeatMapper;
	@Autowired
	WorkSiteSchedulingMapper workSiteSchedulingMapper;
	@Autowired
	WorkSeatSchedulingMapper workSeatSchedulingMapper;

	@Autowired
	IWorkerService workerService;
	@Autowired
	IWorkOrderService workOrderService;
	@Autowired
	IWorkOrderBookService workOrderBookService;
	@Autowired
	IWorkSiteSchedulingService workSiteSchedulingService;
	@Autowired
	IWorkSeatSchedulingService workSeatSchedulingService;

	/**
	 * 查询上门组某一天的摄控安排情况 <b>Description:</b><br>
	 * 
	 * @param queryDO
	 * @return ResultDO
	 * @Note <b>Author:</b> Reading.Reagan <br>
	 *       <b>Date:</b> 2018年9月20日 上午10:36:38 <br>
	 *       <b>Version:</b> 1.0
	 */
	@Override
	public ResultDO queryByDay(SchedulingQueryDO queryDO) {

		ResultDO result = new ResultSupport();
		// 1. 参数验证
		if (isNumberInValid(queryDO.getSiteID()) || StringUtils.isEmpty(queryDO.getSchedulingDateStr())) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			return result;
		}

		// 2.查询满足条件的工位数据
		Map<String, Object> params = new HashMap<String, Object>();
		if (!isNumberInValid(queryDO.getSiteID())) {
			params.put("siteID", queryDO.getSiteID());
		}
		if (StringUtils.isNotEmpty(queryDO.getSchedulingDateStr())) {
			params.put("schedulingDate", new Date(Long.parseLong(queryDO.getSchedulingDateStr())));
		}
		if (StringUtils.isNotEmpty(queryDO.getQueryValue())) {
			String value = queryDO.getQueryValue();
			if ("1".equals(queryDO.getQueryKey())) {
				params.put("vechileCode", value);
			} else if ("2".equals(queryDO.getQueryKey())) {
				params.put("workerName", "%" + value + "%");
			} else if ("3".equals(queryDO.getQueryKey())) {
				params.put("nameOrTel", "%" + value + "%");
			} else if ("4".equals(queryDO.getQueryKey())) {
				params.put("yyEmployee", "%" + value + "%");
			}
		}

		if (queryDO.isPage()) {
			params.put("limitByPage", queryDO.getStart() + "," + queryDO.getPageRows());
			int count = workSiteSeatMapper.countByCondition(params);
			result.setModel(ResultDO.SECOND_MODEL_KEY, count);
		}

		List<WorkSiteSeat> siteSeatList = workSiteSeatMapper.selectByCondition(params);
		List<WorkSiteSeatDO> doList = new ArrayList<WorkSiteSeatDO>();
		if (null == siteSeatList || siteSeatList.size() < 1) {
			result.setModel(ResultDO.FIRST_MODEL_KEY, doList);
			result.setModel(ResultDO.THIRD_MODEL_KEY, Arrays.asList(new Integer[] { 0, 0 }));
			return result;
		}

		List<WorkerDO> srcRoleList = getRoleList();
		for (int i = 0; i < siteSeatList.size(); i++) {
			WorkSiteSeatDO siteSeatDO = getWorkSiteSeatDO(siteSeatList.get(i));
			// 设置默认角色
			List<WorkerDO> roleList = new ArrayList<WorkerDO>();
			roleList.addAll(srcRoleList);
			siteSeatDO.setWorkerList(roleList);
			// 查询工位服务人员（摄影师、育婴师、规划师三个角色， 未设置服务人员时，显示默认角色数据）
			WorkerQueryDO query = new WorkerQueryDO();
			query.setSiteSeatID(siteSeatDO.getId());
			ResultDO result2 = workerService.queryBySiteSeat(query);
			if (result2.isSuccess()) {
				List<WorkerDO> list = (List<WorkerDO>) result2.getModel(ResultDO.FIRST_MODEL_KEY);
				for (WorkerDO data : list) {
					for (int j = 0; j < siteSeatDO.getWorkerList().size(); j++) {
						WorkerDO srcData = siteSeatDO.getWorkerList().get(j);
						// 服务人员
						if (data.getRoleID().equals(srcData.getRoleID())) {
							siteSeatDO.getWorkerList().set(j, data);
							break;
						}
					}
				}
			}

			// 查询席位数据
			ResultDO resultDO = workSeatSchedulingService.listBySiteSeatID(siteSeatDO.getId());
			if (!resultDO.isSuccess()) {
				result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
				result.setErrorMsg("席位数据查询失败");
				result.setSuccess(false);
				return result;
			}

			List<WorkSeatSchedulingDO> seatDOList = (List<WorkSeatSchedulingDO>) resultDO
					.getModel(ResultDO.FIRST_MODEL_KEY);
			siteSeatDO.setSeatList(seatDOList);
			// 查询预约的工单信息
			if (null != siteSeatDO.getSeatList() && siteSeatDO.getSeatList().size() > 0) {
				for (int j = 0; j < siteSeatDO.getSeatList().size(); j++) {
					WorkSeatSchedulingDO seatSchedulingDO = siteSeatDO.getSeatList().get(j);
					if (seatSchedulingDO.getStatus() == BonConstant.SEAT_STATUS_USED) {
						// 席位占用时，查询席位的工单信息
						WorkOrderBookQueryDO queryDO2 = new WorkOrderBookQueryDO();
						queryDO2.setSeatID(seatSchedulingDO.getId()); // 席位ID
						ResultDO result3 = workOrderBookService.query(queryDO2);
						if (result3.isSuccess()) {
							List<WorkOrderBookDO> list = (List<WorkOrderBookDO>) result3
									.getModel(ResultDO.FIRST_MODEL_KEY);
							if (null != list && list.size() > 0) {
								seatSchedulingDO.setWorkOrderBookDO(list.get(0));
							}
						}
					}
				}
			}
			doList.add(siteSeatDO);
		}

		result.setModel(ResultDO.FIRST_MODEL_KEY, doList);

		// 查询席位数及占用数
		int count1 = 0;
		int count2 = 0;
		if (null != doList && doList.size() > 0) {
			WorkSiteSchedulingDO data = new WorkSiteSchedulingDO();
			data.setId(doList.get(0).getSiteSchedulingID());
			count1 = workSiteSchedulingService.countSeatNum(data, BonConstant.SEAT_STATUS_USED);
			count2 = workSiteSchedulingService.countSeatNum(data, null);
		}
		result.setModel(ResultDO.THIRD_MODEL_KEY, Arrays.asList(new Integer[] { count1, count2 }));
		return result;
	}

	@Override
	public WorkSiteSeatDO getSiteSeatByID(Integer id) {
		if (isNumberInValid(id)) {
			return null;
		}
		WorkSiteSeat entity = workSiteSeatMapper.selectByPrimaryKey(id);

		WorkSiteSeatDO data = new WorkSiteSeatDO();
		BeanUtilsExtends.copy(data, entity);
		return data;
	}

	/**
	 * 设置服务等级 <b>Description: 设置服务等级</b><br>
	 * 
	 * @param domain
	 * @return ResultDO
	 * @Note <b>Author:</b> Reading.Reagan <br>
	 *       <b>Date:</b> 2018年9月17日 下午5:47:17 <br>
	 *       <b>Version:</b> 1.0
	 */
	@Override
	public ResultDO setServiceClass(WorkSiteSeatDO domain) {
		// TODO 安排等级
		ResultDO result = new ResultSupport();
		if (isNumberInValid(domain.getId()) || isNumberInValid(domain.getServiceClass())) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			return result;
		}

		WorkSiteSeat entity = new WorkSiteSeat();
		entity.setId(domain.getId());
		entity.setServiceClass(domain.getServiceClass());
		int ret = workSiteSeatMapper.updateByPrimaryKeySelective(entity);
		if (ret < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("服务等级设置失败");
			result.setSuccess(false);
			return result;
		}
		return result;
	}

	/**
	 * 设置服务区域 <b>Description: 设置服务区域</b><br>
	 * 
	 * @param domain
	 * @return ResultDO
	 * @Note <b>Author:</b> Reading.Reagan <br>
	 *       <b>Date:</b> 2018年9月17日 下午5:47:17 <br>
	 *       <b>Version:</b> 1.0
	 */
	@Override
	public ResultDO setRegion(WorkSiteSeatDO domain) {
		// TODO 设置服务区域
		ResultDO result = new ResultSupport();
		if (isNumberInValid(domain.getId()) || StringUtils.isEmpty(domain.getDistrict())) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			return result;
		}

		// 更新数据
		WorkSiteSeat entity = new WorkSiteSeat();
		entity.setId(domain.getId());
		entity.setProvince(domain.getProvince());
		entity.setCity(domain.getCity());
		entity.setDistrict(domain.getDistrict());
		int ret = workSiteSeatMapper.updateByPrimaryKeySelective(entity);
		if (ret < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("服务区域设置失败");
			result.setSuccess(false);
			return result;
		}
		return result;
	}

	/**
	 * 设置车辆 <b>Description: 同一天同一辆车可以分配两组</b><br>
	 * 
	 * @param domain
	 * @return ResultDO
	 * @Note <b>Author:</b> Reading.Reagan <br>
	 *       <b>Date:</b> 2018年9月17日 下午5:47:17 <br>
	 *       <b>Version:</b> 1.0
	 */
	@Override
	public ResultDO setVechile(WorkSiteSeatDO domain) {
		// TODO Auto-generated method stub
		ResultDO result = new ResultSupport();
		// 1.参数验证
		if (isNumberInValid(domain.getId()) || StringUtils.isEmpty(domain.getVechileCode())) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			return result;
		}
		// 2.通过id查询当天日程ID
		WorkSiteSeat siteSeat = workSiteSeatMapper.selectByPrimaryKey(domain.getId());

		// 3.查询车辆设置是否超限（每辆车每日只能安排2次）
		WorkSiteSeatExample example = new WorkSiteSeatExample();
		WorkSiteSeatExample.Criteria criteria = example.createCriteria();
		criteria.andSiteSchedulingIDEqualTo(siteSeat.getSiteSchedulingID());
		criteria.andVechileCodeEqualTo(domain.getVechileCode());
		criteria.andIdNotEqualTo(domain.getId()); //排除当前工位
		criteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);
		List<WorkSiteSeat> list = workSiteSeatMapper.selectByExample(example);
		if (null != list && list.size() >= BonConstant.SCHEDULING_VECHILE_MAX) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("该车辆今日已排满");
			result.setSuccess(false);
			return result;
		}

		// 设置车辆
		WorkSiteSeat entity = new WorkSiteSeat();
		entity.setId(domain.getId());
		entity.setVechileCode(domain.getVechileCode());
		int ret = workSiteSeatMapper.updateByPrimaryKeySelective(entity);
		if (ret < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("服务等级设置失败");
			result.setSuccess(false);
			return result;
		}
		return result;
	}

	/**
	 * 删除工位组 <b>Description:</b><br>
	 * 
	 * @param ids
	 * @return ResultDO
	 * @Note <b>Author:</b> Reading.Reagan <br>
	 *       <b>Date:</b> 2018年9月17日 下午2:55:03 <br>
	 *       <b>Version:</b> 1.0
	 */
	@Override
	public ResultDO deleteGroup(WorkSchedulingSettingDO domain) {
		ResultDO result = new ResultSupport();
		// 1.基础数据验证
		if (isNumberInValid(domain.getSiteID())) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("上门组ID为空");
			result.setSuccess(false);
			return result;
		}

		// 2.查询分组序号
		WorkSiteSeatExample siteSeatExample = new WorkSiteSeatExample();
		WorkSiteSeatExample.Criteria siteSeatCriteria = siteSeatExample.createCriteria();
		siteSeatCriteria.andSiteIDEqualTo(domain.getSiteID());
		siteSeatCriteria.andIdIn(Arrays.asList(domain.getSiteSeatIDs()));
		siteSeatCriteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);
		List<WorkSiteSeat> siteSeatList = workSiteSeatMapper.selectByExample(siteSeatExample);
		if (null == siteSeatList || siteSeatList.size() < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("工位分组为空");
			result.setSuccess(false);
			return result;
		}

		List<Integer> seatGroupIndexList = new ArrayList<Integer>();
		for (WorkSiteSeat data : siteSeatList) {
			seatGroupIndexList.add(data.getSeatGroupIndex());
		}

		// 3.查询摄控区间内的所有分组
		siteSeatExample = new WorkSiteSeatExample();
		siteSeatCriteria = siteSeatExample.createCriteria();
		siteSeatCriteria.andSiteIDEqualTo(domain.getSiteID());
		siteSeatCriteria.andSchedulingDateBetween(new Date(Long.parseLong(domain.getSchedulingDateStart())),
				new Date(Long.parseLong(domain.getSchedulingDateEnd())));
		siteSeatCriteria.andSeatGroupIndexIn(seatGroupIndexList);
		siteSeatCriteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);
		siteSeatList = workSiteSeatMapper.selectByExample(siteSeatExample);
		if (null == siteSeatList || siteSeatList.size() < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("席位为空");
			result.setSuccess(false);
			return result;
		}

		// 4.循环删除
		List<Integer> siteSeatIds = new ArrayList<Integer>();
		for (WorkSiteSeat data : siteSeatList) {
			// 判断分组下的席位是否已被占用
			WorkSchedulingSettingDO settingDO = new WorkSchedulingSettingDO();
			settingDO.setSiteSeatID(data.getId());
			if (!workSeatSchedulingService.checkSeatEnable(settingDO)) {
				result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
				result.setErrorMsg("该分组包含工单，不可删除");
				result.setSuccess(false);
				return result;
			}
			siteSeatIds.add(data.getId());
		}

		// 未被占用，则删除席位数据（更新状态）
		workSeatSchedulingService.deleteByIds(siteSeatIds, domain.getModifiID(), domain.getModifi());

		// 删除分组数据
		delete(siteSeatIds);

		return result;
	}

	@Override
	public ResultDO delete(List<Integer> ids) {
		// TODO Auto-generated method stub
		ResultDO result = new ResultSupport();
		// 1.参数验证
		if (null == ids || ids.size() < 1) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			return result;
		}

		WorkSiteSeatExample example = new WorkSiteSeatExample();
		WorkSiteSeatExample.Criteria criteria = example.createCriteria();
		criteria.andIdIn(ids);
		criteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);

		WorkSiteSeat record = new WorkSiteSeat();
		record.setIsDelete(BonConstant.DB_DELETE);
		record.setModifitime(Calendar.getInstance().getTime());

		workSiteSeatMapper.updateByExampleSelective(record, example);

		return result;
	}

	@Override
	public ResultDO delBySiteScheduling(SchedulingQueryDO queryDO) {
		ResultDO result = new ResultSupport();
		// 1.基础数据验证
		if (isNumberInValid(queryDO.getSiteID())) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("数据转换失败");
			result.setSuccess(false);
			return result;
		}

		// 查询工位分组
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		WorkSiteSeatExample siteSeatExample = new WorkSiteSeatExample();
		WorkSiteSeatExample.Criteria siteSeatcriteria = siteSeatExample.createCriteria();
		siteSeatcriteria.andSiteIDEqualTo(queryDO.getSiteID());
		if (StringUtils.isNotEmpty(queryDO.getSchedulingDateStr())) {
			siteSeatcriteria.andSchedulingDateEqualTo(new Date(Long.parseLong(queryDO.getSchedulingDateStr())));
		}
		siteSeatcriteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);

		List<WorkSiteSeat> list = workSiteSeatMapper.selectByExample(siteSeatExample);
		List<Integer> ids = new ArrayList<Integer>();
		for (WorkSiteSeat data : list) {
			ids.add(data.getId());
		}
		// 删除分配的服务人员
		WorkerQueryDO queryDO2 = new WorkerQueryDO();
		queryDO2.setSiteSeatIDs(ids);
		workerService.delete(queryDO2);

		// 删除工位分组
		WorkSiteSeat siteSeatEntity = new WorkSiteSeat();
		siteSeatEntity.setIsDelete(BonConstant.DB_DELETE);
		siteSeatEntity.setModifitime(Calendar.getInstance().getTime());
		int ret = workSiteSeatMapper.updateByExampleSelective(siteSeatEntity, siteSeatExample);
		if (ret < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("席位更新失败");
			result.setSuccess(false);
			return result;
		}

		// 删除席位
		WorkSeatSchedulingExample seatExample = new WorkSeatSchedulingExample();
		WorkSeatSchedulingExample.Criteria seatCriteria = seatExample.createCriteria();
		seatCriteria.andSiteIDEqualTo(queryDO.getSiteID());
		seatCriteria.andSiteSeatIDIn(ids);
		seatCriteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);

		WorkSeatScheduling seatEntity = new WorkSeatScheduling();
		seatEntity.setIsDelete(BonConstant.DB_DELETE);
		seatEntity.setModifitime(Calendar.getInstance().getTime());

		ret = workSeatSchedulingMapper.updateByExampleSelective(seatEntity, seatExample);
		if (ret < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("席位更新失败");
			result.setSuccess(false);
			return result;
		}
		return result;
	}

	/**
	 * 根据员工/部门查询工位分组及席位 <b>Description:</b><br>
	 * 
	 * @param domain
	 * @return ResultDO
	 * @Note <b>Author:</b> Reading.Reagan <br>
	 *       <b>Date:</b> 2018年9月26日 上午10:57:31 <br>
	 *       <b>Version:</b> 1.0
	 */
	public ResultDO queryByWorker(SchedulingQueryDO queryDO) {

		ResultDO result = new ResultSupport();
		List<WorkSeatSchedulingDO> doList = new ArrayList<WorkSeatSchedulingDO>();

		List<Integer> siteSeatIDs = new ArrayList<Integer>(); // 工位分组ids
		// 1. 参数验证(验证用户id以及部门id)
		if (!isNumberInValid(queryDO.getEmployeeID()) || !isNumberInValid(queryDO.getOrgID())) {
			// 通过员工/部门查询工位数据
			WorkerQueryDO workerQueryDO = new WorkerQueryDO();
			workerQueryDO.setEmployeeID(queryDO.getEmployeeID());
			workerQueryDO.setOrgID(queryDO.getOrgID());
			workerQueryDO.setSchedulingDateStr(queryDO.getSchedulingDateStr());

			result = workerService.queryWorker(workerQueryDO);
			if (!result.isSuccess()) {
				result.setErrorCode(ResultDO.PARAM_ERROR);
				result.setErrorMsg("工位信息查询失败");
				result.setSuccess(false);
				return result;
			}
			List<WorkerDO> workerDOList = (List<WorkerDO>) result.getModel(ResultDO.FIRST_MODEL_KEY);
			if (null == workerDOList || workerDOList.size() < 1) {
				result.setModel(ResultDO.FIRST_MODEL_KEY, doList);
				result.setModel(ResultDO.SECOND_MODEL_KEY, 0);
				return result;
			}
			// 查询工位id（避免重复）
			for (int i = 0; i < workerDOList.size(); i++) {
				if (!siteSeatIDs.contains(workerDOList.get(i).getSiteSeatID())) {
					siteSeatIDs.add(workerDOList.get(i).getSiteSeatID()); // 避免重复查询
				}
			}
		}

		// 2.查询工位数据
		WorkSiteSeatExample example = new WorkSiteSeatExample();
		WorkSiteSeatExample.Criteria criteria = example.createCriteria();

		if (!isNumberInValid(queryDO.getSiteID())) {
			criteria.andSiteIDEqualTo(queryDO.getSiteID());
		}
		if (StringUtils.isNotEmpty(queryDO.getSchedulingDateStr())) {
			criteria.andSchedulingDateEqualTo(new Date(Long.parseLong(queryDO.getSchedulingDateStr())));
		}
		if (siteSeatIDs.size() > 0) {
			criteria.andIdIn(siteSeatIDs);
		}
		criteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);
		example.setOrderByClause(" id asc, seatGroupIndex asc ");
		List<WorkSiteSeat> siteSeatList = workSiteSeatMapper.selectByExample(example);

		Map<Integer, WorkSiteSeat> siteSeatMap = new HashMap<Integer, WorkSiteSeat>();
		for (int i = 0; i < siteSeatList.size(); i++) {
			siteSeatMap.put(siteSeatList.get(i).getId(), siteSeatList.get(i));
			siteSeatIDs.add(siteSeatList.get(i).getId());
		}

		// 3.查询席位数据
		WorkSeatSchedulingExample seatExample = new WorkSeatSchedulingExample();
		WorkSeatSchedulingExample.Criteria seatCriteria = seatExample.createCriteria();
		seatCriteria.andSiteSeatIDIn(siteSeatIDs);
		seatCriteria.andIsDeleteEqualTo(BonConstant.DB_NORMAL);
		// 跳过禁用的席位
		seatCriteria.andStatusNotEqualTo(BonConstant.SEAT_STATUS_DISABLE);
		seatExample.setOrderByClause(" schedulingDate asc, seatGroupIndex asc, planStartOn asc ");

		if (queryDO.isPage()) {
			seatExample.setLimitByPage(queryDO.getStart() + "," + queryDO.getPageRows());
			int count = workSeatSchedulingMapper.countByExample(seatExample);
			result.setModel(ResultSupport.SECOND_MODEL_KEY, count);
		}

		List<WorkSeatScheduling> seatList = workSeatSchedulingMapper.selectByExample(seatExample);
		if (null == seatList || seatList.size() < 1) {
			result.setModel(ResultDO.FIRST_MODEL_KEY, doList);
			return result;
		}

		for (int i = 0; i < seatList.size(); i++) {
			WorkSeatSchedulingDO data = getWorkSeatSchedulingDO(seatList.get(i));
			if (siteSeatMap.containsKey(data.getSiteSeatID())) {
				WorkSiteSeat siteSeat = siteSeatMap.get(data.getSiteSeatID());
				data.setVechileCode(siteSeat.getVechileCode());
				data.setServiceClass(siteSeat.getServiceClass());
				if (!isNumberInValid(data.getServiceClass())) {
					// TODO: 服务接口调用
					// DictionariesDO dic =
					// dicClientAPI.get(obj.getServiceClass());
					// dst.setServiceClassName(dic.getDataItem());
					data.setServiceClassName("七星级");
				}
			}
			doList.add(data);
		}

		result.setModel(ResultDO.FIRST_MODEL_KEY, doList);
		return result;
	}

	/** 查询拍摄工作的服务人员角色 */
	private List<WorkerDO> getRoleList() {
		List<WorkerDO> workerList = new ArrayList<WorkerDO>();

		WorkerRoleQueryDO query = new WorkerRoleQueryDO();
		query.setWorkType(BonConstant.WORK_TYPE_PHOTOGRAPHY);
		ResultDO resultDO = workerService.listRoleByWorkType(query);
		if (resultDO.isSuccess()) {
			List<WorkerRoleDO> roleList = (List<WorkerRoleDO>) resultDO.getModel(ResultDO.FIRST_MODEL_KEY);
			for (int i = 0; i < roleList.size(); i++) {
				WorkerDO worker = new WorkerDO();
				worker.setRoleID(roleList.get(i).getId());
				worker.setRole(roleList.get(i).getRole());
				worker.setRoleCode(roleList.get(i).getCode());
				workerList.add(worker);
			}
		}
		return workerList;
	}

}
